using System;
using CodeAngel.Domain.Framework;

namespace CodeAngel.Domain
{
	public partial class FilterRelationCollection
    {

        #region GetAll
        
        /// <summary>
        /// To identify all the data elements within this collection, including all children.
        /// </summary>
        public FilterRelationCollection GetAll()
        {
            var FilterRelations = new FilterRelationCollection(null);
            foreach (var ThisFR in this)
            {
                FilterRelations.Add(ThisFR);
                foreach (var ChildDE in ThisFR.FilterRelations.GetAll())
                {
                    FilterRelations.Add(ChildDE);
                }
            }
            return FilterRelations;
        }

        #endregion

        #region Find
        
        /// <summary>
        /// Finds the FilterRelation for the identified PropertyDef, searching this 
        /// collection and any of its children.  Returns null if not found.
        /// </summary>
        public FilterRelation Find(PropertyDef thisPD)
        {
            foreach (var ThisFR in this)
            {
                if (ThisFR.PropertyDef.IsSomething())
                {
                    if (ThisFR.PropertyDef.PropertyDefID.Equals(thisPD.PropertyDefID))
                        return ThisFR;

                    if (ThisFR.FilterRelations.Count > 0)
                    {
                        FilterRelation ChildFR = ThisFR.FilterRelations.Find(thisPD);
                        if (ChildFR.IsSomething())
                            return ChildFR;
                    }
                }
            }
            return null;
        }

        #endregion

    }
}

